/*
 * @Author: szx
 * @Date: 2021-12-05 13:22:39
 * @LastEditTime: 2021-12-05 14:07:57
 * @Description:
 * @FilePath: \leetcode\300-399\372\372.js
 */
/**
 * @param {number} a
 * @param {number[]} b
 * @return {number}
 */
var superPow = function (a, b) {
    const MOD = 1337;

    const dfs = (a, b, u) => {
        if (u == -1) return 1;
        return (pow(dfs(a, b, u - 1), 10) * pow(a, b[u])) % MOD;
    };
    const pow = (a, b) => {
        ans = 1;
        a %= MOD;
        while (b-- > 0) ans = (ans * a) % MOD;
        return ans;
    };
    return dfs(a, b, b.length - 1);
};
console.log(superPow(2147483647, [2, 0, 0]));
